<?php

namespace app\mobile\controller;

use app\admin\model\News as ModelNews;
use app\common\controller\Frontend;

class News extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
        //查询新闻，每页显示条数
        $list = ModelNews::where('status',1)->paginate(5);
        //获取分页显示
        $page = $list->render();
        //模板变量赋值
        $this->assign('list',$list);
        $this->assign('page',$page);
        return $this->view->fetch();
    }

    public function info()
    {
        $id = input('id');
        $newsinfo = ModelNews::where('status',1)->where('id',$id)->find();
        //上一条
        $pre_id = ModelNews::where('status',1)->where("id", "<", $id)->limit('1')->find();
        //下一条
        $next_id = ModelNews::where('status',1)->where("id", ">", $id)->limit('1')->find();
        //模板变量赋值
        $this->assign('info',$newsinfo);
        $this->assign('pre',$pre_id);
        $this->assign('next',$next_id);
        //渲染页面
        return $this->view->fetch();
    }
}
